package mytest.simple.watcher;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

public class WatcherTask implements Runnable {
	private ZooKeeper zookeeper;
	private String path = "/watcher";
	
	public WatcherTask() {}
	
	public WatcherTask(ZooKeeper zookeeper) {
		this.zookeeper = zookeeper;
	}

	@Override
	public void run() {
		try {
			Stat stat = zookeeper.setData(path, "foo".getBytes(), 0);
			zookeeper.exists(path, true);
			zookeeper.delete(path, -1);
			zookeeper.exists(path, true);
			System.out.println("stat状态：" + stat);
		} catch (KeeperException | InterruptedException e) {
			e.printStackTrace();
		}
	}
}
